---
title: "Inversion publica 2006-2022"
author: "Ada Cueto - Alexander Sucre"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
theme:
version: 4
base_font:
google: Sen
code_font:
google: JetBrains Mono
bootswatch: darkly
---
```{r setup, include=FALSE}
rm(list = ls())
pacman::p_load(
flexdashboard,
tidyverse,
sparklyr,
readxl,
dplyr,
ggplot2,
GGally,
ggthemes,
plotly,
DataExplorer,
textshape,
reticulate,
tictoc,
parquetize,
knitr,
DT
)
sc <- spark_connect(master = "local")
proy <- spark_read_csv(sc, name = "proyecto", path = "../_data/Proyectos.csv",memory = F)
```
# Resumen {data-icon="fa-home"}
```{r}
```
Row
-----------------------------------------------------------------------
### Cantidad de proyectos {.value-box}
```{r}
tot_proy <- proy %>% count() %>% rename(total=n) %>% collect()
valueBox(tot_proy, icon = "fa-database",color = "info")
```
### Total presupuesto inicial {.value-box}
```{r}
tot_pres <- proy %>% summarise(total=round(sum(Presupuesto_inicial),2)) %>% collect()
valueBox(tot_pres, icon = "fa-dollar-sign",color = "primary")
```
### Total presupuesto vigente {.value-box}
```{r}
tot_vig <- proy %>%
mutate(total=ifelse(!is.na(presupuesto_vigente) & presupuesto_vigente > 0,presupuesto_vigente,Presupuesto_inicial)) %>%
summarize(total = round(sum(total),2)) %>% collect()
valueBox(tot_vig, icon = "fa-chart-line",color = "danger")
```
### Total ejecutado {.value-box}
```{r}
tot_ejec <- proy %>% summarise(total=round(sum(presupuesto_ejecutado,na.rm = TRUE),2)) %>% collect()
valueBox(tot_ejec, icon = "fa-money-bill-alt",color = "success")
```
### % ejecutado
```{r}
por_ejec <- round(tot_ejec/tot_vig*100)
gauge(por_ejec$total, min = 0, max = 100, symbol = "%",
gaugeSectors(
success = c(0,por_ejec$total)
))
```
Row
-----------------------------------------------------------------------
### Presupuestado vs Ejecutado
```{r}
gest <- proy %>%
select(gestion,inicial=Presupuesto_inicial,vigente=presupuesto_vigente,ejecutado=presupuesto_ejecutado) %>%
group_by(gestion) %>%
summarise(inicial=sum(inicial),vigente=sum(vigente),ejecutado=sum(ejecutado)) %>%
arrange(gestion) %>%
collect()
fig <- plot_ly(gest, x = ~gestion, y = ~inicial, type = 'scatter', mode = 'lines', fill = 'tozeroy', name = 'Inicial',fillcolor = 'primary')
fig <- fig %>% add_trace(y = ~vigente, name = 'Vigente',fillcolor = 'danger')
fig <- fig %>% add_trace(y = ~ejecutado, name = 'Ejecutado',fillcolor = 'info')
fig <- fig %>% layout(
xaxis = list(title = 'Gestión'),
yaxis = list(title = 'Monto en millones de dolares'),
title = 'Comparación de presupuesto inicial, vigente y ejecutado por gestión'
)
fig
```
Row
-----------------------------------------------------------------------
### Cantidad de proyectos por departamento
```{r}
dep <- proy %>% count(depto) %>% rename(Departamento=depto,Cantidad=n)
dep_local <- collect(dep)
datatable(dep_local,options = list(paging=FALSE,searching=FALSE,info=FALSE))
```
### Porcentaje de proyectos por departamento
```{r}
dep <- proy %>% count(depto) %>% mutate(porcentaje = n/sum(n)*100) %>% select(Departamento=depto,Porcentaje=porcentaje)
dep_local <- collect(dep)
plot_ly(dep_local,labels=~Departamento,values=~Porcentaje,type = "pie") %>%
layout(title="Proyectos por departamento",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
```
# Graficos {data-navmenu="Analisis" data-icon="fa-signal"}
## Sidebar {.sidebar}
# Tablas {data-navmenu="Analisis" data-icon="fa-list"}
```{r}
datatable(iris)
```
# Informe